@namespace MudBlazor
@inherits MudComponentBase
@typeparam T

<li @attributes="UserAttributes" class="@Classname" style="@Style">
    <div class="@ContentClassname" @onclick="OnItemClicked" @onclick:stopPropagation="true" @ondblclick="OnItemDoubleClicked" @ondblclick:stopPropagation="true">
        @if (Content != null)
        {
            @Content
        }
        else
        {
            <MudTreeViewItemToggleButtonOld Loading="Loading" Expanded="Expanded" ExpandedChanged="OnItemExpanded" Visible="@HasChild" ExpandedIcon="@ExpandedIcon" ExpandedIconColor="@ExpandedIconColor" LoadingIcon="@LoadingIcon" LoadingIconColor="LoadingIconColor"></MudTreeViewItemToggleButtonOld>

            @if (MudTreeRoot != null && MudTreeRoot.MultiSelection)
            {
                <MudCheckBox T="bool" Class="mud-treeview-item-checkbox" CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" @bind-Checked="IsChecked" Disabled="@Disabled"></MudCheckBox>
            }

            @if (!string.IsNullOrEmpty(Icon))
            {
                <div class="mud-treeview-item-icon">
                    <MudIcon Icon="@Icon" Color="@IconColor" />
                </div>
            }

            @if (BodyContent != null)
            {
                @BodyContent(this)
            }
            else
            {
                <MudText Typo="@TextTypo" Class="@TextClassname">
                    @Text
                </MudText>

                @if (!string.IsNullOrEmpty(EndText))
                {
                    <MudText Typo="@EndTextTypo" Class="@EndTextClass">
                        @EndText
                    </MudText>
                }

                @if (!string.IsNullOrEmpty(EndIcon))
                {
                    <div class="mud-treeview-item-icon">
                        <MudIcon Icon="@EndIcon" Color="@EndIconColor" />
                    </div>
                }
            }
        }
    </div>
    @if (HasChild)
    {
        <MudCollapse Expanded="@Expanded">
            <CascadingValue Value="@MudTreeRoot" IsFixed="true">
                <CascadingValue Value="this" IsFixed="true">
                    <MudTreeViewOld Items="Items" ItemTemplate="MudTreeRoot.ItemTemplate" Class="mud-treeview-group">
                        @ChildContent
                    </MudTreeViewOld>
                </CascadingValue>
            </CascadingValue>
        </MudCollapse>
    }
</li>
